using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnergyConsumptionLink:MonoBehaviour {

	public Mob targetMob;
	Mob selfMob;
	private void Start() {
		selfMob=GetComponent<Mob>();
	}

	float previousEnergy;
	private void Update() {

		if(selfMob.energy<previousEnergy) {
			float energyConsumed = previousEnergy-selfMob.energy;
			targetMob.energy-=energyConsumed;
		}

		if(targetMob.energy<=0) selfMob.energy=0;
		else {
			previousEnergy=targetMob.energy;
			selfMob.energyMax=previousEnergy;
			selfMob.energy=previousEnergy;
		}
	}

}
